#include "adx.h"
#include "dbusadaptor.h"
#include "aboutdlg.h"
#include "quitdlg.h"


// PC management routines
void Adx::onLogout()
{
	QColor col = QApplication::palette().color(QPalette::Highlight);
	QuitDlg *dlg = new QuitDlg(QuitDlg::fLogout);
	sysId = dlg->winId();
	int f = dlg->exec();
	delete dlg;
	sysId = 0;
	if (f == QDialog::Accepted) {
		wmCleanup();
		quit();
	}
	// quick workaround "Highlight color disappear" bug
	setHighlightColor(col);
}

void Adx::onPCSleep()
{
    if (hal)
        hal->call("Suspend", 0);
}

void Adx::onPCRestart()
{
    if (hal) {
        QColor col = QApplication::palette().color(QPalette::Highlight);
        QuitDlg *dlg = new QuitDlg(QuitDlg::fReboot);
        sysId = dlg->winId();
        int f = dlg->exec();
        delete dlg;
        sysId = 0;
        if (f == QDialog::Accepted) {
            wmCleanup();
            hal->call("Reboot");
            quit();
        }
        // quick workaround "Highlight color disappear" bug
        setHighlightColor(col);
    }
}

void Adx::onPCShutdown()
{
    if (hal) {
        QColor col = QApplication::palette().color(QPalette::Highlight);
        QuitDlg *dlg = new QuitDlg(QuitDlg::fHalt);
        sysId = dlg->winId();
        int f = dlg->exec();
        delete dlg;
        sysId = 0;
        if (f == QDialog::Accepted) {
            wmCleanup();
            hal->call("Shutdown");
            quit();
        }
        // quick workaround "Highlight color disappear" bug
        setHighlightColor(col);
    }
}

// Show Antico Deluxe "About this..." dialog
void Adx::onAbout()
{
	QColor col = QApplication::palette().color(QPalette::Highlight);
	AboutDlg *dlg = new AboutDlg(MAJOR_VERSION, MINOR_VERSION, QString(MODIFICATION));
	sysId = dlg->winId();
	dlg->exec();
	delete dlg;
	sysId = 0;
	// quick workaround "Highlight color disappear" bug
	setHighlightColor(col);
}
